package com.wzapp.sitposture.config.redission;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 功能: <br/>
 *
 * @author ql
 * @create 2018-11-13 17:25
 **/
@Component
@Configuration
@EnableAutoConfiguration
public class RedissonConfig {

    @Value("${spring.redis.password}")
    private String password;

//    @Bean(destroyMethod = "shutdown")
//    @Profile("prod")
//    RedissonClient redissonProduction() throws IOException {
//
//        Config config = new Config();
//        config.useSingleServer().setPassword(password).setAddress("xxxx:6379");
//        RedissonClient redisson = Redisson.create(config);
//        return redisson;
//    }

    @Bean(destroyMethod = "shutdown")
    @Profile("dev")
    RedissonClient redissonDeveloper() throws IOException {
        Config config = new Config();
        config.useSingleServer().setAddress("localhost:6379");
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

    @Bean(destroyMethod = "shutdown")
    @Profile("prod")
    RedissonClient redissonTest() throws IOException {
        Config config = new Config();
        config.useSingleServer().setAddress("localhost:6379");
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }


}
